package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.StockMapper;
import com.zld.smarket.dto.StockList;
import com.zld.smarket.pojo.Stock;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockServiceImpl implements StockService {

    @Autowired
    private StockMapper stockMapper;

    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<StockList> StockLists = stockMapper.selectAllAndPage(page,limit);
        Long count = Long.valueOf(StockLists.size());


        return new ResponseData(StockLists,count);
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<StockList> stockLists =  stockMapper.search(s,page,limit);
        Long count = Long.valueOf(stockLists.size());
        return new ResponseData(stockLists,count);
    }

    @Override
    public List<Stock> selectbyGoodsno(Long goodsNo,Long supplier,Long storehouse) {
        List<Stock> stocks = stockMapper.selectbyGoodsno(goodsNo,supplier,storehouse);
        return stocks;
    }

    @Override
    public Integer addStockNum(Long goodsNo,Long supplier,Long storehouse,Long stockinNum) {
        return stockMapper.addStockNum(goodsNo,supplier,storehouse,stockinNum);
    }

    @Override
    public Integer addStock(Stock stock) {
        int j=0;
        j=stockMapper.insertStockin(stock);
        return j;
    }

    @Override
    public Integer reduceStockNum(Long goodsNo, Long supplierId, Long storehouseNo, Long stockoutNum) {
        return stockMapper.reduceStockNum(goodsNo,supplierId,storehouseNo,stockoutNum);
    }

    @Override
    public ResponseData stateSearch(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<StockList> stockLists =  stockMapper.stateSearch(s,page,limit);
        Long count = Long.valueOf(stockLists.size());
        return new ResponseData(stockLists,count);
    }


}
